# 登录 得到cookie
import requests
from lxml import etree

# 会话
session = requests.session()

# 登录
url = "http://www.xbiqugu.net/login.php?jumpurl=http://www.xbiqugu.net/"
data = {
    "LoginForm[username]": "上风",
    "LoginForm[password]": "gmh487126..",
    "usecookie": "0",
    "action": "login"
}
header = {
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
    "Accept-Encoding": "gzip, deflate",
    "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
    "Cache-Control": "max-age=0",
    "Connection": "keep-alive",
    "Content-Length": "78",
    "Content-Type": "application/x-www-form-urlencoded",
    "Cookie": "_abcde_qweasd=0",
    "Host": "www.xbiqugu.net",
    "Origin": "http://www.xbiqugu.net",
    "Referer": "http://www.xbiqugu.net/",
    "Upgrade-Insecure-Requests": "1",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0"
}

# session会话登录
res = session.post(url, data=data, headers=header)
# print(res.text)
print(res.status_code)

# 获取书架页面数据
bookcase = session.get("http://www.xbiqugu.net/modules/article/bookcase.php")
print(bookcase.status_code)
print(bookcase.text)
result = etree.HTML(bookcase.text)

# 解析书架数据
tbody = result.xpath("//*[@id='checkform']/table/tr")
for tr in tbody:
    a = tr.xpath("./td/a/text()")
    if len(a) > 0:
        print(a[0])
